import { useDispatch } from "react-redux";
import store from "@/store";
import { useMemo } from "react";
import { renderMenuItem } from "@/routes";
import { useLocation } from "react-router-dom";
type TDispatch = typeof store.dispatch;
export const useAppDispatch = () => useDispatch<TDispatch>();
export const useAppTilte = () => {
    const location = useLocation();
    return useMemo(() => {
        // const path ="/" + location.pathname.split("/")[1];
        // 思路：useMemo
        // const titleObj = useMemo(()=>{
        const path = "/" + location.pathname.split("/")[1];
        // 根据路由path找到路由信息
        const info = renderMenuItem().find((v: any) => v.path === path);
        // 找到一级标题
        const title = info.label;
        // 找二级标题
        let subTitle;
        if (info.children) {
            const subInfo = info.children.find((v: any) => v.path === location.pathname);
            if (subInfo) subTitle = subInfo.label;
        }
        return {
            title,
            subTitle
        }
    }, [location.pathname])
}
